import {myFetch} from '@/assets/js/utils'

export default{
    // 获取商品分类
    async getCategories(){
		const data = await myFetch({
				name: 'shopping.sys.category.info'
			})
		return data
	},
	// 获取分类下商品列表 page为0时获取分类下全部商品
	async getGoodsList({classAppendId, classId, page}){
		const data = await myFetch({
			name: 'shopping.sys.catagory.goods',
			class_append_id: classAppendId,
			class_id: classId,
			type: 1,
			page
		})
		return data
	},
	// 搜索商品
	async search({search, page}){
		const data = await myFetch({
			name: 'shopping.sys.search.goods',
			search,
			type: 1,
			page
		})
		return data
	},
	// 获取商品详情
	async getGoodsDetail(preGoodsId){
		const data = await myFetch({
			name: 'shopping.sys.goods.info',
			pre_goods_id: preGoodsId
		})
		return data
	},
	// 获取商品图片信息
	async getGoodsDetailPic(preGoodsId){
		const data = await myFetch({
			name: 'shopping.sys.goods.detail.pic',
			pre_goods_id: preGoodsId
		})
		return data
	},
	// 获取商品额外属性
	async getGoodsAttrs(preGoodsId){
		const data = await myFetch({
			name: 'shopping.sys.goods.attribute',
			pre_goods_id: preGoodsId
		})
		return data
	},
	// 获取商品额外属性可提供搭配
	async getGoodsAttrsMatch(preGoodsId) {
		const data = await myFetch({
			name: 'shopping.sys.AllAvailableAttribute',
			pre_goods_id: preGoodsId
		})
		return data
	},
	// 选择额外属性 获取商品goodsId及其价格存货
	async getGoodsId({preGoodsId, attrIds}){
		const data = await myFetch({
			name: 'shopping.sys.goods.detail',
			pre_goods_id: preGoodsId,
			attribute: attrIds
		})
		return data
	},
	// 获取商品评论
	async getGoodsComments({preGoodsId, type, page}){
		const data = await myFetch({
			name: 'shopping.sys.goods.comment',
			pre_goods_id: preGoodsId,
			type,
			page
		})
		return data
	},
	// 底下和user相关
	// 收藏商品
	async collectGoods(goodsId){
		const data = await myFetch({
			name: 'shopping.sys.collect',
			for_id: goodsId,
			for_type: 'pre_goods'
		})
		return data
	},
	// 取消收藏
	async uncollectGoods(preGoodsId){
		const data = await myFetch({
			name: 'shopping.sys.collect.cancel',
			for_id: preGoodsId,
			for_type: 'pre_goods'
		})
		return data
	},
	// 获取收藏列表
	async getCollection(page){
		const data = await myFetch({
			name: 'shopping.sys.collect.list',
			for_type: 'pre_goods',
			user_id: 0,
			page
		})
		return data
	}
}